<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%option explicit%>
<%
Dim RZ_IN
RZ_IN=1
%>
<!--#include file="../conn.inc.asp" -->
<!--#include file="admin_inc/admin.function.asp" -->
<!--#include file="admin_inc/admin.sqlfunction.asp" -->
<%
checkadmin(4)
Dim act
act=Trim(request.querystring("act"))
If act="save" Then
Call Save()
response.redirect("type_list.asp")
End If 
Sub Save()
Dim x,id,perpage,theorder
For Each x In Request.Form
	If Left(x,9)="theorder_" Then 
		id=Mid(x,10)
		theorder=Trim(request.Form(x))
		perpage=Trim(request.Form("perpage_"&id))
		If isNumber(theorder) Then 
			If isNumber(perpage) Then 
			conn.Execute("update [c_type] set theorder="&theorder&", perpage="&perpage&" where id="&id&"")
			Else
			conn.Execute("update [c_type] set theorder="&theorder&" where id="&id&"")
			End If 
		End If 
	End If 
Next 
Call SetTypeProperties()
End Sub 
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>分类设置</title>
<link type="text/css" href="style/style.css" rel="stylesheet" rev="stylesheet"/>
<script type="text/javascript" src="admin_js/common.js"></script>
</head>
<body>
<div>
<div class="addrecord">
<select id="addtype" onchange="javascript:location.href=this.options[this.selectedIndex].value">
	<option value="type_list.asp">=添=加=分=类=</option>
	<option value="type_add.asp?thefenlei=1">文章资讯</option>
	<option value="type_add.asp?thefenlei=2">商品资讯</option>
	<option value="type_add.asp?thefenlei=3">图片资讯</option>
	<option value="type_add.asp?thefenlei=6">单页分类</option>
	<option value="type_add.asp?thefenlei=7">招聘信息</option>
	<option value="type_add.asp?thefenlei=4">外部链接</option>
	<option value="type_add.asp?thefenlei=5">留言本</option>
</select>

</div>
<br />
<center><span style="color:red;">
提示：要查看分类的前台访问地址，请点击<img src="images/modify.gif" width="14" height="15" alt="修改" />“修改”图标。</span>
</center>
<form method="post" action="type_list.asp?act=save">
<table class="table_800" cellspacing="0" cellpadding="0">
<th class='tdcenter'>ID</th>
<th class='tdcenter'>分类名称（中）</th>
<th class='tdcenter'>分类名称（英）</th>
<th class='tdcenter'>模板</th>
<th class='tdcenter'>记录</th>
<th class='tdcenter'>排序</th>
<th class='tdcenter'>显隐</th>
<th class='tdcenter'>分页大小</th>
<th class='tdcenter'>路径</th>
<th class='tdcenter'>操作</th>
</tr>
<%
dim rst,sqlt,rowcount,fenlei,visible,pre
Set rst = Server.CreateObject("ADODB.Recordset")
sqlt = "select * from [c_type] where parentid=0 order by theorder"
rst.open sqlt,conn,1,1
rowcount=1
Do While Not rst.eof
	rowcount=rowcount+1	
	response.write("<tr class='row'>")
	response.write("<td class='tdcenter'>")
	response.write(rst("id"))
	response.write("</td>")
	response.write("<td>")
	response.write("<a href='")
	If rst("url")<>"" Then
	response.write("#' title='"&rst("url")&"'")
	Else
	fenlei=rst("fenlei")
	Select Case fenlei
		Case 1:
		response.write("article_list.asp")
		Case 2:
		response.write("product_list.asp")
		Case 3:
		response.write("photo_list.asp")
		End Select
	response.write("?id="&rst("id")&"'")
	End If 
	response.write("><strong>"&rst("name")&"</strong></a>")
	If rst("recordtemplate")="" Then response.write("<sup>*</sup>")
	response.write("</td>")
	response.write("<td>")
	response.write(rst("engname"))
	response.write("</td>")
	fenlei=rst("fenlei")
	response.write("<td class='tdcenter'>")
	Select Case fenlei
		Case 1:
		response.write("文章资讯")
		pre="文章"
		Case 2:
		response.write("商品信息")
		pre="商品"
		Case 3:
		response.write("普通图片")
		pre="图片"
		Case 4:
		response.write("外部链接")
		Case 5:
		response.write("留言本")
		pre="留言"
		Case 6:
		response.write("单页分类")
		pre="单页"
		Case 7:
		response.write("招聘信息")
		pre="招聘"
	End Select
	response.write("</td>")
	response.write("<td>")
	Dim recount
	recount=CaculateRecord(rst("path"),fenlei)
	If fenlei=1 Or fenlei=2 Or fenlei=3 Or fenlei=7 Then 
	response.write(recount)
	End If 
	response.write("</td>")
	response.write("<td>")
	response.write("<input id='theorder_"&rst("id")&"' name='theorder_"&rst("id")&"' value='"&rst("theorder")&"' size='2' onkeyup=""this.value=this.value.replace(/[^\d]+?/g,'')""/>")
	response.write("</td>")
	visible=rst("visible")
	response.write("<td>")
		If visible="0" Then
		response.write("隐藏")
		Else
		response.write("显示")
		End If 
	response.write("</td>")
	response.write("<td>")
	'If rst("havechild")=1 Then 
	'response.write("有")
	'Else
	'response.write("无")
	'End If 
	If fenlei=1 Or fenlei=2 Or fenlei=3 Or fenlei=5 Or fenlei=7 Then 
	response.write("<input id='perpage_"&rst("id")&"' name='perpage_"&rst("id")&"' value='"&rst("perpage")&"' size='2' onkeyup=""this.value=this.value.replace(/[^\d]+?/g,'')""/>")
	Else
	response.write("&nbsp;")
	End If 
	response.write("</td>")
	response.write("<td>"&CutPath(rst("path"))&"</td>")
	response.write("<td>")
	If fenlei<>4 Then 
	response.write("<a href='type_add.asp?parentid="&rst("id")&"' title='添加"&pre&"子分类'")
	If recount>0 And rst("havechild")=0 Then 
	response.write("onclick=""javascript:alert('该分类已经有记录，添加子分类后您务必要将原来的记录移动到新的子分类中。\n\r本系统不允许在非最终分类添加内容，否则生成HTML会出错');""")
	End If 
	response.write("><img src='images/add.gif' alt='添加"&pre&"子分类' border='0'/></a>&nbsp;")
	response.write("<a href='type_add.asp?outlink=1&parentid="&rst("id")&"' title='添加外部链接'><img src='images/link.gif' alt='添加外部链接' border='0'/></a>&nbsp;")
	'response.write("<a href='type_add.asp?outlink=2&parentid="&rst("id")&"' title='添加单页分类'><img src='images/single.gif' alt='添加单页分类' border='0'/></a>&nbsp;")
	End If 
	response.write("<a href='type_edit.asp?id="&rst("id")&"' title='修改'><img src='images/modify.gif' alt='修改' border='0'/></a>&nbsp;")
	If rst("havechild")=0 Then
		response.write("<a onclick=""return confirm('您确定要删除吗？本操作会清空所有子类及分类下的所有记录');"" href='type_delete.asp?id="&rst("id")&"&pid="&rst("parentid")&"' title='删除'><img src='images/delete.gif' alt='删除' border='0'/></a>&nbsp;")
	Else 
		response.write("<a onclick=""alert('请先删除子分类');"" href='#' title='删除'><img src='images/delete.gif' alt='删除' border='0'/></a>&nbsp;")
	End If 
	If fenlei=1 Or fenlei=2 Or fenlei=3 Then
		If rst("thelevel")>0 Then 
		response.write("<a href='type_move.asp?id="&rst("id")&"' title='移动'><img src='images/move.gif' alt='移动' border='0'/></a>")
		End If 
		response.write("&nbsp;<a href='type_union.asp?id="&rst("id")&"' title='合并'><img src='images/union.gif' alt='合并' border='0'/></a>&nbsp;")
	End If
	response.write("</td>")
	response.write("</tr>")
	PrintChild(rst("id"))
rst.movenext
Loop
rst.close
Set rst=Nothing
%>
<%
Function PrintChild(parentid)
dim rsp,sqlp,rowcount,i,fenlei
Set rsp = Server.CreateObject("ADODB.Recordset")
sqlp = "select * from [c_type] where parentid="&parentid&" order by theorder"
rsp.open sqlp,conn,1,1

Do While Not rsp.eof
	rowcount=rowcount+1	
	response.write("<tr class='row'>")
	response.write("<td class='tdcenter'>")
	response.write(rsp("id"))
	response.write("</td>")
	response.write("<td>")
	For i=1 To rsp("thelevel")-2
	response.write("&nbsp;&nbsp;")
	Next
	If rsp("thelevel")>2 Then
	response.write("└")
	End If 
	response.write("<a href='")
	If rsp("url")<>"" Then
	response.write("#' title='"&rsp("url")&"'")
	Else
	fenlei=rsp("fenlei")
	Select Case fenlei
		Case 1:
		response.write("article_list.asp")
		Case 2:
		response.write("product_list.asp")
		Case 3:
		response.write("photo_list.asp")
		End Select
	response.write("?id="&rsp("id")&"'")
	End If 
	response.write(">"&rsp("name")&"</a>")
	If rsp("recordtemplate")="" Then response.write("<sup>*</sup>")
	response.write("</td>")
		response.write("<td>")
	response.write(rsp("engname"))
	response.write("</td>")
	fenlei=rsp("fenlei")
	response.write("<td class='tdcenter'>")
	Select Case fenlei
		Case 1:
		response.write("文章资讯")
		pre="文章"
		Case 2:
		response.write("商品信息")
		pre="商品"
		Case 3:
		response.write("普通图片")
		pre="图片"
		Case 4:
		response.write("外部链接")
		Case 5:
		response.write("留言本")
		pre="留言"
		Case 6:
		response.write("单页分类")
		pre="单页"
		Case 7:
		response.write("招聘信息")
		pre="招聘"
	End Select
	response.write("</td>")
	response.write("<td>")
	Dim recount
	recount=CaculateRecord(rsp("path"),fenlei)
	If fenlei=1 Or fenlei=2 Or fenlei=3 Or fenlei=7 Then 
	response.write(recount)
	End if
	response.write("</td>")
	response.write("<td>")
	response.write("<input id='theorder_"&rsp("id")&"' name='theorder_"&rsp("id")&"' value='"&rsp("theorder")&"' size='2' onkeyup=""this.value=this.value.replace(/[^\d]+?/g,'')""/>")
	response.write("</td>")
	visible=rsp("visible")
	response.write("<td>")
		If visible="0" Then
		response.write("隐藏")
		Else
		response.write("显示")
		End If 
	response.write("</td>")
	response.write("<td>")
	'If rsp("havechild")=1 Then 
	'response.write("有")
	'Else
	'response.write("无")
	'End If 
	If fenlei=1 Or fenlei=2 Or fenlei=3 Or fenlei=5 Or fenlei=7 Then 
	response.write("<input id='perpage_"&rsp("id")&"'  name='perpage_"&rsp("id")&"' value='"&rsp("perpage")&"' size='2' onkeyup=""this.value=this.value.replace(/[^\d]+?/g,'')""/>")
	Else
	response.write("&nbsp;")
	End If 
	response.write("</td>")
	response.write("<td>"&CutPath(rsp("path"))&"</td>")
	response.write("<td>")
	If fenlei<>4 And fenlei<>5 And fenlei<>7 Then 
	response.write("<a href='type_add.asp?parentid="&rsp("id")&"' title='添加"&pre&"子分类'")
	If recount>0 And rsp("havechild")=0 Then 
	response.write("onclick=""javascript:alert('该分类已经有记录，添加子分类后您务必要将原来的记录移动到新子的分类中。\n\r本系统不允许在非最终分类添加内容，否则生成HTML会出错');""")
	End If 
	response.write("><img src='images/add.gif' alt='添加"&pre&"子分类' border='0'/></a>&nbsp;")
	response.write("<a href='type_add.asp?outlink=1&parentid="&rsp("id")&"' title='添加外部链接'><img src='images/link.gif' alt='添加外部链接' border='0'/></a>&nbsp;")
	'response.write("<a href='type_add.asp?outlink=2&parentid="&rsp("id")&"' title='添加单页分类'><img src='images/single.gif' alt='添加单页分类' border='0'/></a>&nbsp;")
	End If 
	response.write("<a href='type_edit.asp?id="&rsp("id")&"' title='修改'><img src='images/modify.gif' alt='修改' border='0'/></a>&nbsp;")
	If rsp("havechild")=0 Then
	response.write("<a onclick=""return confirm('您确定要删除吗？本操作会清空所有子类及分类下的所有记录');"" href='type_delete.asp?id="&rsp("id")&"&pid="&rsp("parentid")&"' title='删除'><img src='images/delete.gif' alt='删除' border='0'/></a>&nbsp;")
	Else 
	response.write("<a onclick=""alert('请先删除子分类');"" href='#' title='删除'><img src='images/delete.gif' alt='删除' border='0'/></a>&nbsp;")
	End If 
	If fenlei=1 Or fenlei=2 Or fenlei=3 Then 
		If rsp("thelevel")>2 Then 
		response.write("<a href='type_move.asp?id="&rsp("id")&"' title='移动'><img src='images/move.gif' alt='移动' border='0'/></a>")
		End If 
		response.write("&nbsp;<a href='type_union.asp?id="&rsp("id")&"' title='合并'><img src='images/union.gif' alt='合并' border='0'/></a>&nbsp;")
	End If 
	response.write("</td>")
	response.write("</tr>")
	PrintChild(rsp("id"))
rsp.movenext
Loop
rsp.close
Set rsp=Nothing
End Function 

Function CaculateRecord(temppath,myfenlei)
dim tablename,rsc,sqlc,recount
select case myfenlei
case 1:
	tablename="c_article"
case 2:
	tablename="c_product"
case 3:
	tablename="c_photo"
case 5:
	tablename="c_comment"
case else:
	tablename=""
end select
if tablename<>"" then
Set rsc = Server.CreateObject("ADODB.Recordset")
sqlc = "select count(id) as recount from "&tablename&" where  Instr(path,'"+temppath+"')>0"
rsc.open sqlc,conn,1,1
If Not rsc.eof Then 
recount=rsc("recount")
End If 
rsc.close
Set rsc=Nothing
else
recount="0"
end if
CaculateRecord=recount
End Function 
%>
<tr><td colspan="10" class="tdcenter">
<input type="submit" class="btn" value="保存"/>
</td></tr>
</table>
<br/>
	
</form>

</div>

<form method="post" action="type_save.asp">
<table class="table_500" cellspacing="0" cellpadding="0">
<tr><td align="center" style="border:0px">
<input type="hidden" name="act" value="updatepathname">	
<input type="submit"  class="btn" value="如果分类路径出错，请点击这里刷新">
</td></tr>
</table>
</form>


</body>
</html>